<?php
/**
* Products_model
* A model-representation of the products in the database.
*/
class Products_model extends CI_Model {
	private $dbTable = 'ws_products';
	
	public function __construct() {
	    parent::__construct();
	}
	
	/**
	* GetProducts
	* Gets all the products form the database.
	* @param string orderBy What column to order the result by.
	* @param string order Order the result by descending or ascending order. Random works too.
	* @return Array with all the products.
	*/
	public function GetProducts( $orderBy = 'name', $order = 'desc' ) {
	    // Set the orderby and order to the query.
		$query = $this->db->order_by( $orderBy, $order );
		
		// Executes the query to get all the products.
	    $query = $this->db->get( $this->dbTable );
		
		// return the result as an array.
		return $query->result_array();
	}
	
	/**
	* GetProductById
	* Get a product from the database with the specified ProductID.
	* @param int productId The ID of the product.
	* @return Array With the specified object.
	*/
	public function GetProductById( $productId ) {
	    $query = $this->db->get_where( $this->dbTable, array( 'ProductID' => $productId ) );
        
		return $query->result_array();
	}
}